<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>${sysName}</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="${resRoot}/layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="${resRoot}/layui/admin/admin.css" media="all" />
	<link id="layuicss-layer" rel="stylesheet" href="${resRoot}/layui/css/modules/layer/default/layer.css" media="all">
</head>
<body class="childrenBody">
	<div class="layui-fluid">   
          <div class="layui-card">
	<div class="layui-form layui-card-header layuiadmin-card-header-auto">
	<div class="layui-form-item">
		<div class="layui-inline">
		    <a class="layui-btn search_btn layui-btn-normal">查询</a>
		</div>
		<div class="layui-inline">
			<a class="layui-btn linksAdd_btn" style="background-color:#5FB878" href="javascript:void(0);">添加用户</a>
		</div>
	</div>
	</div>
	
	
	<div class="layui-card-body">
	
	
	<div class="layui-form news_list">
	  	<table class="layui-table">
		    <colgroup>
				<col>
				<col>
				<col>
				<col>
				<col>
		    </colgroup>
		    <thead>
				<tr>
					<th>序号</th>
					<th style="text-align:left;">用户名</th>
					<th>昵称</th>
					<th>邮箱</th>
					<th>手机</th>
					<th>操作</th>
				</tr>
		    </thead>
		    <tbody>
		    	<#list result.datas as user>
		    	<tr>
		    		<td>${(result.pageNumber - 1)*result.pageSize + user_index+1}</td>
					<td style="text-align:left;">${user.loginName}</td>
					<td>${user.name}</td>
					<td>${user.email}</td>
					<td>${user.phone}</td>
					<td><a class="layui-btn layui-btn-normal layui-btn-xs" onclick="addData('${user.id}')" href="javascript:void(0);"  ><i class="iconfont icon-edit"></i>修改</a> 
		        		<a class="layui-btn layui-btn-danger layui-btn-xs" href="javascript:void(0);" onclick="deleteUser(${user.id});" ><i class="layui-icon"></i>删除</a>
		        		<a class="layui-btn layui-btn-xs" href="javascript:void(0);" onclick="resetPassword(${user.id});" ><i class="iconfont"></i>重置密码</a>
		        	</td>
				</tr>
				</#list>
			</tbody>
		</table>
	</div>
	<div id="page"></div>
	</div>
	</div>
	<script type="text/javascript" src="${resRoot}/layui/layui.js"></script>
	<script src="${resRoot}/js/jquery.min.js?v=2.1.4"></script>
	<script src="${resRoot}/layui/layui.all.js" charset="utf-8"></script>
	<#assign pageUrl=base+'/sys/user/userlist?'>
	<#include "/page/page1.html">
	<script>
	$(".search_btn").click(function(){
		  window.location.reload();
	  });
	  		function deleteUser(id){	
  			 if(confirm("确定要删除用户?")){
  				 $.ajax({
  		    		 type : "post",
  		    		 url : "${base}/sys/user/deleteUser?",
  		    		 data : {
  		    			  id : id
  		    			 },
  					 dataType : "json",
  					 async : false,
  					 success : function(data) {
  						 flag  = data.message;
  							if(flag != 0) {
  								layer.msg('删除成功！', {
  									  icon: 1,
  									  time: 2000 //2秒关闭（如果不配置，默认是3秒）
  									}, function(){
  									  //do something
  										window.location.href="${base}/sys/user/userlist";
  									});  

  								
  							} else {
  								layer.alert("数据错误，请完善数据！");
  							}
  					 }
  		    	 });
  			}
		}
	  		
	  		function resetPassword(id) {
	  			var flag = 0;
	  			layer.confirm('确定重置荐该用户密码吗?', function(index){
	  				$.ajax({
	  					type : "post",
	  					url : "${base}/sys/user/resetPassword",
	  					data : {
	  						id : id
	  					},
	  					dataType : "json",
	  					async : false,
	  					success : function(data) {
	  						flag  = data.message;
	  						if(flag == 1) {
	  							layer.msg('重置成功！', {
	  							  icon: 1,
	  							  time: 2000 //2秒关闭（如果不配置，默认是3秒）
	  							}, function(){
	  								window.location.reload();
	  							});   
	  						} else {
	  							layer.alert("服务器繁忙，请稍候再试！");
	  						}
	  					}
	  				});
	  			});
	  		}
	  		
	  		layui.use(['form','layer','laydate','table','laytpl'],function(){
	  		    var form = layui.form,
	  		        layer = parent.layer === undefined ? layui.layer : top.layer,
	  		        $ = layui.jquery,
	  		        laydate = layui.laydate,
	  		        laytpl = layui.laytpl,
	  		        table = layui.table;
	  		$(".linksAdd_btn").click(function(){
	  			addData();
	  	    })
	  	    /* $("#editData").click(function(){
	  	    	var id = $(this).attr("dataId");
	  	    	addData(id);
	  	    }); */
	  		 })
	  		 
	  		 function addData(id){
		  			var url = "${base}/sys/user/insert";
		  			var titleStr = "添加用户";
		  			if(id){
		  				url = "${base}/sys/user/changeUser?id=" + id;
		  				titleStr = "修改用户";
		  			}
		  	        var index = layui.layer.open({
		  	            title : titleStr,
		  	            type : 2,
		  	            content : url,
		  	            success : function(layero, index){
		  	                var body = layui.layer.getChildFrame('body', index);
		  	                setTimeout(function(){
		  	                    layui.layer.tips('点击此处返回', '.layui-layer-setwin .layui-layer-close', {
		  	                        tips: 3
		  	                    });
		  	                },500)
		  	            }
		  	        })
		  	        layui.layer.full(index);
		  	        //改变窗口大小时，重置弹窗的宽高，防止超出可视区域（如F12调出debug的操作）
		  	        $(window).on("resize",function(){
		  	            layui.layer.full(index);
		  	        })
		  	    }

</script>
</body>
</html>